<template>
  <div class="box">
    <div class="title">登录</div>
    <div class="login_form">
      <div class="login_form_inner">
        <div class="form_item bb">
          <Input class="clr"
                 v-model="formData.phonenum"
                 placeholder="手机号"
                 @on-keydown.13="login"></Input>
        </div>
        <div class="form_item">
          <Input class="clr"
                 v-model="formData.password"
                 type="password"
                 password
                 placeholder="密码"
                 @on-keydown.13="login"></Input>
        </div>
      </div>
      <div class="form_btn">
        <Button type="primary"
                @click="login"
                long>登录</Button>
      </div>
      <div class="form_tip">
        <div class="form_tip_left">还没有账号，<a href="javascript:void(0)"
             @click="goto">去注册</a></div>
      </div>
    </div>

  </div>
</template>

<script>
import { Form, FormItem, Input, Icon, Button } from 'view-design'
export default {
  name: 'Login',
  components: {
    Form, FormItem, Input, Icon, Button
  },
  props: {
    defaultUsername: {
      type: String,
      default: ''
    },
    actionParams: {
      type: Object,
      default () {
        return {}
      }
    }
  },
  data () {
    return {
      formData: {
        phonenum: '',
        password: ''
      },
      loginStatus: -1 // 0: 登录中，-1：未登录，1：已经登录
    }
  },
  created () {
    this.$nextTick(() => {
      if (this.actionParams && this.actionParams.defaultUsername) {
        this.formData.phonenum = this.actionParams.defaultUsername
      } else if (!this.formData.phonenum) {
        this.formData.phonenum = this.defaultUsername
      }
    })
  },
  methods: {
    goto () {
      this.$emit('goto', {
        name: 'register'
      })
    },
    login () {
      if (!this.formData.phonenum) return this.$Message.error({
        content: '手机号不能为空',
        duration: 5
      })
      if (!this.formData.password) return this.$Message.error({
        content: '密码不能为空',
        duration: 5
      })
      // 登录
      this.loginStatus = 0
      bbtools.send('user-login', {
        username: this.formData.phonenum,
        password: this.formData.password
      })
      this.formData.password = ''
    },
  }
}
</script>

<style lang="less" scoped>
@import url("../../themes/index.less");
.box {
  width: 100%;
  height: 100%;
  padding: 20px 10px;
  box-sizing: border-box;
  .title {
    text-align: center;
    margin-bottom: 10px;
    margin-left: 5%;
    color: @lightTextColor3;
    font-size: 18px;
    font-family: "webfont" !important;
  }
  .login_form {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    &_inner {
      width: 90%;
      height: 80px;
      background-color: rgba(96, 96, 96, 0.3);
      border-radius: 8px;
      .form_item {
        width: 100%;
        height: 40px;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: flex-start;
        &.bb {
          border-bottom: 1px solid @lightDividerColor;
        }
      }
    }
    .form_btn {
      width: 90%;
      margin-top: 20px;
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-content: center;
    }
    .form_tip {
      margin-top: 20px;
      width: 90%;
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-content: space-between;
      color: @lightTextColor3;
      font-size: 12px;
      &_left {
        a {
          cursor: pointer;
        }
      }
      &_right {
        cursor: pointer;
      }
    }
  }
}
</style>